package com.zhangh.summer.admin.controller.auth;

import com.fasterxml.jackson.core.JsonEncoding;
import com.zhangh.summer.admin.model.bo.AuthBO;
import com.zhangh.summer.admin.model.bo.DataBO;
import com.zhangh.summer.admin.support.base.JsonResponse;
import com.zhangh.summer.admin.biz.auth.AuthBiz;
import com.zhangh.summer.admin.biz.menu.MenuBiz;
import com.zhangh.summer.admin.model.bo.MenuBO;
import com.zhangh.summer.admin.model.po.AdAuthPO;
import com.zhangh.summer.admin.support.ds.common.pager.DataPager;
import com.zhangh.summer.admin.support.utils.json.JsonEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-10-08 21:21
 **/
@RestController
@RequestMapping(value = "/auth",method = RequestMethod.POST)
public class AuthController {
    @Autowired
    private AuthBiz authBiz;
    @Autowired
    private MenuBiz menuBiz;

    @RequestMapping("/dataPager")
    public String dataPager(@RequestBody DataBO query) {
        DataPager<AdAuthPO> dataPager=this.authBiz.getAuthDataPager(query,query.getPager());
        return new JsonResponse().toJson(dataPager);
    }

    @RequestMapping("/getAuth/{id}")
    public String getAuth(@PathVariable Long id) {
        AuthBO authBO=this.authBiz.getAuthBO(id);
        System.out.println(JsonEncoder.DEFAULT.encode(authBO));
        return new JsonResponse().toJson(authBO);
    }

    @RequestMapping("/save")
    public String save(@RequestBody AuthBO authBO) {
        long c1=this.authBiz.saveAuthBO(authBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/update")
    public String update(@RequestBody AuthBO authBO) {
        int c1=this.authBiz.updateAuthBO(authBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/delete")
    public String delete(@RequestBody DataBO dataBO) {
        int c1=this.authBiz.deleteAuth(dataBO.getId());
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/getAuthMenu/{id}")
    public String getAuthMenu(@PathVariable Long id) {
        List<MenuBO> menuBOList=this.menuBiz.getAuthMenuList(id);
        return new JsonResponse().toJson(menuBOList);
    }

    @RequestMapping("/getAuthMenuListForCheck")
    public String getAuthMenuListForCheck() {
        List<MenuBO> menuBOList=this.menuBiz.getAuthMenuListForCheck(0L);
        return new JsonResponse().toJson(menuBOList);
    }

    @RequestMapping("/dataList")
    public String dataList() {
        List<AdAuthPO> list=this.authBiz.getAuthList();
        return new JsonResponse().toJson(list);
    }




}
